package com.otitan.la.forest.system.controller;

import com.otitan.auth.framework.basepro.config.HasPermission;
import com.otitan.la.forest.system.dto.DownloadZipDTO;
import com.otitan.la.forest.system.dto.FileDTO;
import com.otitan.la.forest.system.entity.FileInfoEntity;
import com.otitan.la.forest.system.dto.FileInfoDTO;
import com.otitan.la.forest.system.vo.FileInfoVO;
import com.otitan.la.forest.system.service.FileInfoService;
import com.otitan.webapp.framework.basepro.model.DataResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.websocket.OnOpen;
import java.util.ArrayList;
import java.util.List;

/**
 *  
 *
 * @author sunke
 * @email xxx
 * @date 2020-10-15 09:22:53
 */
@Slf4j
@Api(tags = "附件相关API")
@RestController
@RequestMapping("/file/info")
public class FileInfoController {

    @Autowired
    private FileInfoService fileInfoService;


    /**
     * 新增文件或文件夹记录（不是上传文件）
     * @author Sunke
     * @param  fileInfo, bindingResult
     * @return com.otitan.webapp.framework.basepro.model.DataResult
     * @exception
     * @date 2020/10/15 0015 16:11
     */
    @ApiOperation(value = "新增文件或文件夹记录（不是上传文件）")
    @PostMapping("/add")
    public DataResult add(@RequestBody List<FileInfoEntity> dtoList) {
        return fileInfoService.add(dtoList);
    }

    @ApiOperation(value = "批量删除")
    @DeleteMapping("/batchDelete")
    public DataResult batchDelete(@RequestBody @ApiParam(value = "ID集合") List<String> ids) {
        return fileInfoService.batchDelete(ids);
    }


    @ApiOperation(value = "根据业务ID删除")
    @PostMapping("/batchDeleteByBusiId")
    public DataResult batchDeleteByBusiId(@RequestBody @ApiParam(value = "业务ID集合") List<String> ids) {
        return fileInfoService.batchDeleteByBusiId(ids);
    }

    @ApiOperation(value = "根据文件ID删除文件夹或者文件")
    @PostMapping("/batchDeleteById")
    public DataResult batchDeleteById(@RequestBody @ApiParam(value = "文件ID集合") List<String> ids) {
        return fileInfoService.batchDeleteById(ids);
    }

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    public DataResult editor(@Valid @RequestBody FileInfoEntity fileInfo, BindingResult bindingResult) {
        return fileInfoService.editor(fileInfo, bindingResult);
    }

    @ApiOperation(value = "根据业务ID文件查询")
    @PostMapping("/findByFileId")
    public DataResult<List<FileInfoEntity>> findByFileId(@RequestBody String id) {
        return fileInfoService.findByFileById(id);
    }

//  /**
//  * 文件上传
//  * @author Sunke
//  * @param [file]
//  * @return com.otitan.webapp.framework.basepro.model.DataResult
//  * @exception
//  * @date 2020/10/15 0015 09:38
//  */
//    @ApiOperation(value = "附件（文件）上传")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "file", value = "上传的文件", paramType = "form")
//    })
//    @PostMapping(value = "upload")
//    public DataResult upload(@RequestParam MultipartFile file) {
//        return fileInfoService.upload(file);
//    }

    /**
    * 批量下载
    * @author Sunke
    * @param [response, dto]
    * @return void
    * @exception
    * @date 2020/10/15 0015 09:37
    */
//    @ApiOperation(value = "批量下载")
//    @PostMapping("downloadZip")
//    public void downloadZip(HttpServletResponse response, @RequestBody DownloadZipDTO dto) {
//        fileInfoService.downloadZip(response, dto);
//    }




}
